<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="https://www.thymeleaf.org">
<head>
    <title>顶单商品管理</title>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" media="all" href="/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css">
    <script type="text/javascript" src="/js/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/layui/layui.js"></script>
</head>
<script>
    function updateValues(ID){
        $("#UpdateID").val(ID);
    }
    function deleteValues(ID){
        $("#DeleteID").val(ID);
    }
    function FindOrderProductByType() {
        var id = parseInt($("#orderID").val());
        var type = $("#productType").val();
        data = {
            id: id,
            type: type
        }
        $.ajax({
            url: "selectOrderProductByType",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function FindOrderProductByName() {
        var id = parseInt($("#orderID").val());
        var name = $("#nameSearch").val();
        data = {
            id: id,
            name: name
        }
        $.ajax({
            url: "selectOrderProductByName",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function DeleteOrderProduct(){
        var id = parseInt($("#orderID").val());
        var productID = $("#DeleteID").val();
        var count = $("#count").val();
        data = {
            id: id,
            productID: productID,
            productCount: count
        }
        if(count==""){
            alert("未设置撤销数量！");
        }
        else{
            $.ajax({
                url: "deleteOrderProduct",
                type: "Post",
                data: data,
                datatype: "html",
                success: function (data, status) {
                    $("#roomInformation").replaceWith(data);
                }
            })
            alert("撤销成功!");
        }
    }
    function Back(){
        $.ajax({
            url:"/selectAllThe_order",
            type: "Post",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function WatchGPhoto(ID) {
        data = {
            id: ID
        }
        $.ajax({
            url:"/product/watchGPhoto",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#KGP").replaceWith(data);
            }
        })
    }
</script>
<body>
<div class="container mt-3" id="roomInformation">
    <h2>订单管理界面</h2>
    <br>
    <ul class="nav nav-pills" role="tablist">

        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="nameSearch" placeholder="搜索名称"/>
            </a>
        </li>

        <li><button type="submit" class="btn btn-default" onclick="FindOrderProductByName()">搜索</button></li>

        <div class="producttype">
            <select id="productType" onchange="FindOrderProductByType()" type="button" class="btn btn-light btn-sm">
                <option>请选择商品类型</option>
                <option value="all">全部</option>
                <option value="饮料">饮料</option>
                <option value="零食">零食</option>
                <option value="小吃">小吃</option>
            </select>
        </div>

        <li><button type="button" class="btn btn-light btn-sm" onclick="Back()">返回</button></li>
        <li><input id="orderID" name="orderID" th:value="${orderID}" style="display: none"></li>
        <li><input id="state" name="state" th:value="${state}" style="display: none"></li>
    </ul>
    <div class="tab-content">
        <div id="home" class="container tab-pane active"><br>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>商品号</th>
                    <th>商品名称</th>
                    <th>商品价格</th>
                    <th>类型</th>
                    <th>数量</th>
                    <th>金额</th>
                    <th>图片</th>
                    <th th:if="${state}==0">撤销商品</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="product:${products}">
                    <td th:text="${product.id}"></td>
                    <td th:text="${product.name}"></td>
                    <td th:text="${product.price} + '/' + ${product.unit}"></td>
                    <td th:text="${product.type}"></td>
                    <td th:text="${product.count}"></td>
                    <td th:text="${product.count}*${product.price}"></td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#photo" th:onclick="|javascript:WatchGPhoto('${product.id}')|">查看</button></td>
                    <td th:if="${state}==0"><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#fire" th:onclick="|javascript:deleteValues('${product.id}')|">撤销</button></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal picture" id="photo">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">商品图片</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal" onclick="location.reload()"></button>
            </div>

            <div class="modal-body" id="KGP">
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="location.reload()">关闭</button>
            </div>

        </div>
    </div>
</div>

<div class="modal alter" id="modify">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h4 class="modal-title">更新商品价格</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">商品号</td><td><input id="UpdateID" name="UpdateID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">更新价格</td><td><input id="UpdatePrice" name="UpdatePrice" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="UpdateProduct()">确定</button>
            </div>

        </div>
    </div>
</div>

<div class="modal Fire" id="fire">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">删除商品</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">商品号</td><td><input readonly="readonly" id="DeleteID" name="DeleteID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">撤销数量</td><td><input id="count" name="count" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">是否撤销该商品？</td><td style="height:32px;width:300px;font-size:22px">撤销所选数量的商品</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="DeleteOrderProduct()">是</button>
            </div>

        </div>
    </div>
</div>

</body>
</html>